<?php

class LaravelExcel {

    public $title = "";
    public $labels = "";
    public $data = "";

    function process() {
        error_reporting(E_ALL);
        ini_set('display_errors', TRUE);
        ini_set('display_startup_errors', TRUE);
        //date_default_timezone_set('Europe/London');
        $objPHPExcel = new PHPExcel();
        /* $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
          ->setLastModifiedBy("Maarten Balliauw")
          ->setTitle("Office 2007 XLSX Test Document")
          ->setSubject("Office 2007 XLSX Test Document")
          ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
          ->setKeywords("office 2007 openxml php")
          ->setCategory("Test result file"); */

        $letras = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I');
        $i = 0;
        foreach ($this->labels as $label) {
            $objPHPExcel->setActiveSheetIndex(0)->setCellValue($letras[$i] . '2', $label[1]);
            $i++;
        }

        $pos = 3;
        foreach ($this->data as $values) {
            $i = 0;
            foreach ($values as $value) {
                $objPHPExcel->setActiveSheetIndex(0)->setCellValue($letras[$i] . $pos, $value);
                $i++;
            }
            $pos++;
        }
        

        $objPHPExcel->getActiveSheet()->setTitle($this->title);
        $objPHPExcel->setActiveSheetIndex(0);
        
        $file = str_replace(' ', '_', strtolower($this->title)) ;

        header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
        header('Content-Disposition: attachment;filename="'.$file.'.xlsx"');
        header('Cache-Control: max-age=0');
        // If you're serving to IE 9, then the following may be needed
        header('Cache-Control: max-age=1');

        // If you're serving to IE over SSL, then the following may be needed
        //header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
        header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
        header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
        header('Pragma: public'); // HTTP/1.0

        $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
        $objWriter->save('php://output');
    }

}
